package com.icacoo.cp.business;

import java.util.HashMap;
import java.util.Map;

public class AutoSelectNumber {

	private int resultCount = 6;
	private int blueMaxValue = 33;
	private int redMaxValue = 16;
	private int[] reds;
	private int blue;

	public AutoSelectNumber() {
		this.initialization();
	}

	public void initialization() {
		this.reds = this.generateReds();
		this.blue = this.generateBlue();
	}

	private int[] generateReds() {
		int[] result = new int[resultCount];
		Map<Integer, String> map = new HashMap<Integer, String>();

		for (int i = 0; i < resultCount; i++) {
			result[i] = random(map);
		}
		result = sortArray(result);
		return result;
	}

	private int[] sortArray(int[] result) {
		int count = result.length;
		for (int i = 0; i < count - 1; i++) {
			int min = result[i];
			for (int j = i + 1; j < count; j++) {
				if (min > result[j]) {
					min = result[j];
					result[j] = result[i];
					result[i] = min;
				}
			}
		}
		return result;
	}

	private int random(Map<Integer, String> map) {
		double value = Math.random() * blueMaxValue;
		int v = (int) value;
		if (v == 0)
			v++;
		if (map.containsKey(v)) {
			v = random(map);
		} else {
			map.put(v, "");
		}
		return v;
	}

	private int generateBlue() {
		int result = 0;
		double value = Math.random() * redMaxValue;
		result = (int) value;
		if (result == 0)
			result++;
		return result;
	}

	private boolean isExistToday() {

		return false;
	}

	public int[] getReds() {
		return reds;
	}

	public int getBlue() {
		return blue;
	}
}
